import Vue from "vue";
import VueRouter from "vue-router";

Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    redirect: { name: 'home' }
  },
  {
    name: "home",
    path: "/home",
    component: () => import("@/views/Home/Home.vue")
  },

  {
    name: "car",
    path: "/car",
    component: () => import("@/views/Car/CarList.vue")
  },
  {
    name: "ImgList",
    path: "/ImgList",
    component: () => import("@/views/Images/ImgList.vue")
  },
  {
    name: "GoodsList",
    path: "/GoodsList",
    component: () => import("@/views/Goods/GoodsList.vue"),
  },
  {
    name: "NewsDetial",
    path: "/NewsDetial/:id",
    component: () => import("@/views/News/NewsDetial.vue"),
  },
  {
    name: 'NewsList',
    path: '/NewsList',
    component: () => import('@/views/News/NewsList.vue')
  },
  {
    name: "photo",
    path: "/photo/:id",
    props: true,
    component: () => import("@/views/Images/ImgDetial.vue"),
  },
  {
    name: "goodsInfo",
    path: "/goods/info/:id",
    component: () => import("@/views/Goods/GoodsInfo.vue"),
  },
  {
    name: "goodsDesc",
    path: "/goods/desc/:id",
    component: () => import("@/views/Goods/GoodsDesc.vue"),
  },
  {
    name: "userLogin",
    path: "/login",
    component: () => import("@/views/User/UserLogin.vue"),
  },
  {
    name: "comment",
    path: "/comment/:id",
    component: () => import("@/components/Comment.vue"),
    props: true,
  },
]

const router = new VueRouter({
  routes,
});

/* router.beforeRouteEnter((to, from, next) {
  next(vm => {
    // 回到原来的位置
    const position = JSON.parse(window.sessionStorage.getItem('position'))
    document.querySelector('.list-row').scrollTop = position
  })
});

router.beforeRouteLeave((to, from, next) {
  // 保存离开页面时的位置
  const position = document.querySelector('.list-row').scrollTop
  window.sessionStorage.setItem('position', JSON.stringify(position))
  next()
}) */

export default router;
